import px2rem from 'px2rem'
import loaderUtils from 'loader-utils'
import css from 'css'

// 上一个loader 的内容，或者源代码，经过一些处理，把结果返回下一个laoder， 或者webpack
export function loader(source) {
	// get Options
	let op = loaderUtils.getOptions({ query: { rootVa1ue: 75, unitPrecision: 3 } })
	console.log('%c [  ]-10', 'font-size:13px; background:pink; color:#bf2c9f;', op)

	// let op =  loaderUtils.getOptions(this)
	let mPx2rem = new px2rem(op)
	let targetSource = mPx2rem.generateRem(source) // 生成rem
	const cs = css.parse(source)

	console.log('%c [  ]-17', 'font-size:13px; background:pink; color:#bf2c9f;', JSON.stringify(cs, null, 2))
	// console.log(depth: 100, {})

	console.log('%c [  ]-15', 'font-size:13px; background:pink; color:#bf2c9f;', targetSource)
	return targetSource
}

let source = `
#root {
    height: 100px;
    width: 30px;
    padding: 10px;
}
`
loader(source)
